package com.scuec.groupfive.Controller;

import com.github.pagehelper.PageInfo;
import com.scuec.groupfive.entity.MockExam;
import com.scuec.groupfive.service.MockExamService;
import com.scuec.groupfive.vo.MockExamVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/mockexam")
@CrossOrigin
public class MockExamController {

    @Autowired
    private MockExamService mockExamService;

    // 分页列表显示所有模拟考试记录
    //http://localhost:8080/mockexam/pages
    @GetMapping("/pages")
    public PageInfo<MockExam> getMockExamPages(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return mockExamService.getMockExamPages(pageNum, pageSize);
    }

    // 根据用户名查询模拟考试记录（分页）
    //http://localhost:8080/mockexam/findByUsername?username=student1
    @GetMapping("/findByUsername")
    public PageInfo<MockExamVO> getMockExamByUsername(
            @RequestParam String username,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return mockExamService.getMockExamByUsername(username, pageNum, pageSize);
    }

    // 根据用户名获取模拟考试统计信息
    //http://localhost:8080/mockexam/stats?username=emma_w
    @GetMapping("/stats")
    public Map<String, Object> getExamStatsByUsername(@RequestParam String username) {
        return mockExamService.getExamStatsByUsername(username);
    }
}